﻿/*----------------------------------------------------------------
  //Copyright (C) 2012 赵国伟
  //文件功能描述：商品列表页
  //创建人：赵国伟
  //生成时间：2012/03/17 16:15:00
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Shopping.Common;
using Shopping.Model;
using Shopping.BLL;

public partial class Goods_List :BasePage
{
    protected QueryGoodsAsPage q; //分页查询对象；
    protected List<GoodsInfo> listOfGoods; //商品结果集；
    protected List<News> listOfNews; //点客动态；

    #region "过滤条件"
    protected GoodsFilter filter;

    #endregion

    protected URLManage bllUrl = new URLManage();
    protected string title;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            InitPageInfo();
        }
    }

    #region "初始化页面基本信息"
    /// <summary>
    /// 初始化页面基本信息
    /// </summary>
    private void InitPageInfo()
    {
        q = new QueryGoodsAsPage(true); //初始化查询条件；

        NewsManage bllNews = new NewsManage();
        listOfNews = bllNews.QueryNews(3, CConst.点客动态, true);  //查询点客动态；

        GoodsManage bllGoods = new GoodsManage();
        filter = bllGoods.GetGoodsFilter(q); //加载商品过滤条件选项；
        if (q.Sorts == 0)
            q.Sorts = 7;
        q.Status = Status.正用.ToString();
        q.SaleStatus = GoodsSaleStatus.已上架.ToString();
        q.PageSize = 16;
        listOfGoods = bllGoods.QueryListAsPage(q); //查询商品；

        CategoriesManage bllCategory = new CategoriesManage();
        if (q.TCategoryID > 0)
        {
            ucSCategory.BindData(q.SCategoryID);
            title = bllCategory.GetCategoriesName(q.TCategoryID);
        }
        else
        {
            if (q.SCategoryID > 0)
            {
                ucSCategory.BindData(q.SCategoryID);
                title = bllCategory.GetCategoriesName(q.SCategoryID);
            }
            else
            {
                if (q.FCategoryID > 0)
                {
                    ucFCategory.BindData(q.FCategoryID);
                    title = bllCategory.GetCategoriesName(q.FCategoryID);
                }
                else
                {
                    ucAllCategory.BindData();
                    title = "商品列表";
                }
            }
        }
        if (q.SpecialAreaID > 0)
            title = new DictionariesManage().GetDictionaryInfo(q.SpecialAreaID).DictionaryName + "-" + title;

    }
    #endregion

    #region "获取查询过滤条件的URL"
    /// <summary>
    /// 获取查询过滤条件的URL
    /// </summary>
    /// <param name="filterEnum"></param>
    /// <param name="defaultValue"></param>
    /// <returns></returns>
    protected string GetFilterUrl(FilterEnum filterEnum,int defaultValue)
    {
        QueryGoodsAsPage qp = q.Clone();
        switch (filterEnum)
        {
            case FilterEnum.品牌:
                qp.BrandID = defaultValue;
                break;
            case FilterEnum.产地:
                qp.GoodsPlaceID = defaultValue;
                break;
            case FilterEnum.包装:
                qp.PackUnitID = defaultValue;
                break;
            case FilterEnum.价格:
                qp.GoodsPriceCondID = defaultValue;
                break;
            case FilterEnum.排序:
                qp.Sorts = defaultValue;
                break;
        }
        return bllUrl.GetGoodsListUrl(qp);
    }
    #endregion



}